package com.greenant.store.activity;


import java.util.ArrayList;

import android.app.ActionBar;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;

import com.greenant.store.R;
import com.greenant.store.fragment.GoodsListFragment;
import com.greenant.store.fragment.MyFragmentPagerAdapter;

/**
 * * 
 *
 * 
 * 
 */
public class GoodsPerStyleActivity extends FragmentActivity {
	public static final String STYLE_GOODS_PERSTYLE ="GetGoodsPerStyle";
    private static final String TAG = "GoodsPerStyleActivity";
    private ViewPager mPager;
    private ArrayList<Fragment> fragmentsList;
    private ImageView ivBottomLine;
    private TextView tvTabActivity, tvTabGroups, tvTabFriends;

    private int bottomLineWidth;
    private int offset = 0;
    private int position_one;
    private int position_two;
    
    private Resources resources;
	private ImageView iBack;
	private TextView iAdd,tTitle;
	private String styleName;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    	Intent intent = getIntent();
        super.onCreate(savedInstanceState);
        //requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_goods_per_style);
        resources = getResources();
        
        final ActionBar actionBar = getActionBar();  
        if (actionBar!=null)
        {
	        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);  
	        actionBar.setCustomView(R.layout.actionbar);//�Զ���ActionBar����  
        
            tTitle = (TextView)findViewById(R.id.actionbar_title);
	        iBack = (ImageView)findViewById(R.id.left_btn);
	        iAdd = (TextView)findViewById(R.id.right_btn);
	        
	        styleName=intent.getStringExtra("styleName");
	        tTitle.setText(styleName);  
	        
	        iBack.setOnClickListener(new OnClickListener()
	        {	
				@Override
				public void onClick(View v) {				
	         	    finish();
				}
	        	
	        });
        }        
        InitWidth();
        InitViewPager();
    }   

    private void InitViewPager() {
        mPager = (ViewPager) findViewById(R.id.vPager2);
        fragmentsList = new ArrayList<Fragment>();                
       
     //   ArrayList<GoodsInfo> list=new ArrayList<GoodsInfo>();    
    
        Fragment salingfragment = GoodsListFragment.newInstance(STYLE_GOODS_PERSTYLE,styleName);
        fragmentsList.add(salingfragment);        
        mPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), fragmentsList));
        mPager.setCurrentItem(0);
    }

    private void InitWidth() {
        ivBottomLine = (ImageView) findViewById(R.id.iv_bottom_line);
        bottomLineWidth = ivBottomLine.getLayoutParams().width;
        Log.d(TAG, "cursor imageview width=" + bottomLineWidth);
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int screenW = dm.widthPixels;
        offset = (int) ((screenW  - bottomLineWidth) / 2);
        Log.i("MyStoreActivity", "offset=" + offset);

        position_one = (int) (screenW);
        position_two = position_one * 2;
    }

    public class MyOnPageChangeListener implements OnPageChangeListener {

        @Override
        public void onPageSelected(int arg0) {
            Animation animation = null;
            animation.setFillAfter(true);
            animation.setDuration(300);
            ivBottomLine.startAnimation(animation);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    }
}
